package com.ruipeng.shengyapo.controller;

import com.ruipeng.shengyapo.comm.ResponseData;
import com.ruipeng.shengyapo.service.CouponService;
import com.ruipeng.shengyapo.utils.ContentUtils;
import com.ruipeng.shengyapo.utils.ObjUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by tu_pei on 17/6/13.
 */
@Controller
@RequestMapping("coupon")
public class CouponController {

    @Autowired
    private CouponService couponService;

    @RequestMapping(value = "/{userId}/list",method = RequestMethod.POST)
    @ResponseBody
    public ResponseData userCouponlist(@PathVariable int userId){
        ResponseData data = new ResponseData();
        if(ObjUtils.isEmpty(userId)){
            data.setMsg("用户不存在");
            data.setState(ContentUtils.COMM_STATE_FALSE);
            return data;
        }else {
            data.setResults(couponService.getUserCoupon(userId));
            data.setState(ContentUtils.COMM_STATE_TRUE);
            return data;
        }

    }

}
